package cn.ven.service;

import cn.ven.entity.Comment;
import cn.ven.mapper.CommentMapper;
import cn.ven.tool.SessionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    CommentMapper commentMapper;


    @Override
    public void addComment(Comment comment) {
        comment.setUid(SessionUtil.getId());
        comment.setTcreate(new Date());
        commentMapper.insert(comment);
    }

    @Override
    public List<Comment> findComment(int blogid) {
        LambdaQueryWrapper<Comment> queryWrapper =new LambdaQueryWrapper();
        queryWrapper.eq(Comment::getBlogid,blogid);
        return commentMapper.selectList(queryWrapper);
    }

    @Override
    public void delComment(int id) {
        commentMapper.deleteById(id);
    }


}
